namespace('base.config');

base.config.initSecuritySetting = function(){
	initCheckBox();
	initRadio();
	
	var providers = ($('#providers')==null)?'':$('#providers').val().split(',');
	$('.provider').each(function(){
		var val = $(this).val();
		if(providers.indexOf(val)>-1){
			$(this).attr('checked','checked');
		}
		//添加click事件
		$(this).click(function(){
			var providers = $('#providers').val().split(',');
			//删除空项
			providers.remove(providers.indexOf(''));
			var val = $(this).val();
			if($(this).attr('checked')){
				providers.push(val);
			}else{
				providers.remove(providers.indexOf(val));
			}
			$('#providers').val(providers.join(','));
		})
	});
	
	$('#securityConfigForm').validate({
		rules: {
			'login.providers': 'required',
			'login.maximumSessions': {
				required: true,
				number: true
			},
			'login.maximumException': 'required',
			'password.minLength': {
				required: true,
				number: true
			},
			'password.maxLength': {
				required: true,
				number: true
			},
			'password.age': {
				required: true,
				number: true
			}
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit(function(data){
				if(data.success){
					$('.alert').removeClass('alert-error').addClass('alert-success');	
				}else{
					$('.alert').removeClass('alert-success').addClass('alert-error');	
				}
				$('.alert span').text(data.message);
				$('.alert').slideDown(400).delay(2000).slideUp(1000);
			});
		}
	});
};

base.config.initNotificationSetting = function(){
	initCheckBox();
	initRadio();
	$('#notificationConfigForm').validate({
		rules: {
			'login.providers': 'required',
			'login.maximumSessions': {
				required: true,
				number: true
			},
			'login.maximumException': 'required',
			'password.minLength': {
				required: true,
				number: true
			},
			'password.maxLength': {
				required: true,
				number: true
			},
			'password.age': {
				required: true,
				number: true
			}
		},
		submitHandler: function(form) {
			$(form).ajaxSubmit(function(data){
				if(data.success){
					$('.alert').removeClass('alert-error').addClass('alert-success');	
				}else{
					$('.alert').removeClass('alert-success').addClass('alert-error');	
				}
				$('.alert span').text(data.message);
				$('.alert').slideDown(400).delay(2000).slideUp(1000);
			});
		}
	});
};